$(function () {
    var contextPath;
    $(document).ready(function () {
        contextPath = $('#contextPath').val();
    });

    $('#submit').click(function () {
        var name = $('#name').val();
        var userName = $('#userName').val();
        var passWord = $('#passWord').val();
        if(name==null ||name=='')
        {
            alert("请输入姓名！");
            return;
        }
        if(userName==null ||userName=='')
        {
            alert("请输入用户名！");
            return;
        }
        if(passWord==null ||passWord=='')
        {
            alert("请输入密码！");
            return;
        }

        var data = {name:name,userName:userName,passWord:passWord}
        $.ajax({
            type:'post',
            url:contextPath+'/user/addUser',
            data:data,
            success:function (data) {
                if(data.success == true)
                {
                    window.location.href=contextPath + '/index';
                }
                else
                {
                    alert(data.info);
                    return;
                }

            },
            error:function () {

            }
        });
    });

    $('#reset').click(function () {
        $('#name').val('');
        $('#userName').val('');
        $('#passWord').val('');
    });

    $('#back').click(function () {
        window.location.href=contextPath + '/index';
    });
});